package demo1;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author liangzai
 * @Description:
 */
public class MinStack {
    Deque<Integer> stack;
    Deque<Integer> minstack;

    public MinStack() {
        stack = new LinkedList<>();
        minstack = new LinkedList<>();
        //minstack.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        stack.push(val);
        if (minstack.isEmpty()) {
            minstack.push(val);
        }else {
            minstack.push(Math.min(minstack.peek(), val));
        }
    }

    public void pop() {
        int val = stack.pop();
        minstack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}
